package com.compile;

import java.util.List;

/**
 * Created by zhoulikai on 17/2/17.
 */

public class Main {
    public static void main(String args[]) {

        if (args == null || args.length < 2) {
            new RuntimeException("编译参数错误");
            return;
        }

//        String fileType = "xml";
//        if (args.length > 2) {
//            fileType = args[2];
//        }

        String configureFilePath = args[0];
        String outFilePath = args[1];

//        String configureFilePath = "/Users/zhoulikai/code/GTMCAPP-ANDROID/app/src/main/assets/parameter.xml";
//        String outFilePath = "/Users/zhoulikai/code/GTMCAPP-ANDROID/app/src/main/assets/";
        String fileType = "xml";

        Compile compile = new Compile();
        ParameterClass parameterClass = compile.configureParseFile(configureFilePath, fileType);
        if (parameterClass == null) {
            new RuntimeException("解析失败");
            return;
        }

        //打印解析的数据
        ParameterClass.RootBean rootBean = parameterClass.getRoot();
        if (rootBean != null) {
            System.out.println("\n");
            System.out.println(">>>>>>>>>>>>>数据解析>>>>>>>>>>>>>>>>>>>>>>");
            List<ParameterClass.RootBean.ClassBean> classBeanList = rootBean.getClassX();
            if (classBeanList != null && !classBeanList.isEmpty()) {
                for (int i = 0; i < classBeanList.size(); i++) {
                    ParameterClass.RootBean.ClassBean classBean = classBeanList.get(i);
                    if (classBean != null) {
                        System.out.println("\n");
                        System.out.println(">>>>>>>>>>>>>类名:" + classBean.getName() + ">>>>>类注释：" + classBean.getValue());
                        List<ParameterClass.RootBean.ClassBean.KeyBean> keyBeanList = classBean.getKey();
                        if (keyBeanList != null && !keyBeanList.isEmpty()) {
                            for (int j = 0; j < keyBeanList.size(); j++) {
                                ParameterClass.RootBean.ClassBean.KeyBean keyBean = keyBeanList.get(j);
                                if (keyBean != null) {
                                    System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>变量名:" + keyBean.getName() + ">>>>>变量注释："
                                            + keyBean.getValue() + ">>>>>>>>变量是否可需：" + keyBean.getContent());
                                }
                            }
                        }
                        System.out.println("\n");
                    }
                }
            }
            System.out.println(">>>>>>>>>>>>>数据解析>>>>>>>>>>>>>>>>>>>>>>");
            System.out.println("\n");
        }

        boolean isSuccess = compile.generateJavaFile(parameterClass, outFilePath);
        if (!isSuccess) {
            new RuntimeException("解析失败");
            return;
        }


    }
}
